import scrapy
from scrapy import cmdline
from scrapy.http import JsonRequest, HtmlResponse


class NetEaseJobInfoSpider(scrapy.Spider):
    name = "netease_job_info"
    # allowed_domains = ["hr.163.com"]
    # start_urls = ["http://hr.163.com/"]

    def start_requests(self):
        url = 'https://hr.163.com/api/hr163/position/queryPage'
        for page in range(1, 180):
            payload = {
                "currentPage": page,
                "pageSize": 10,
                "workType": "0"
            }
            yield JsonRequest(url, data=payload)

    def parse(self, response: HtmlResponse, **kwargs):
        print(response.json())


if __name__ == '__main__':
    cmdline.execute('scrapy crawl netease_job_info'.split())


"""
如果需要发送表单数据使用: scrapy.FormRequest
如果需要发送json数据使用: JsonRequest
    from scrapy.http import JsonRequest
"""